package com.platform.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.collect.Maps;
import com.platform.comm.enums.BaseEnum;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Description: 配置取值模式
 *
 * @author libin Created on 2019/7/18
 **/
public enum ConfValueMode implements BaseEnum<String> {

    // 字符串
    Num("0", "数值"),
    Str("1", "文本"),
    InSingle("2", "单选"),
    InMulti("3", "多选"),
    PicTure("4","图片");


    private final String value;

    private final String text;

    ConfValueMode(String value, String text) {
        this.value = value;
        this.text = text;
    }

    public static ConfValueMode getByValue(String value) {
        if (value.equals(ConfValueMode.Str.value)) {
            return Str;
        } else if (value.equals(ConfValueMode.InSingle.value)) {
            return InSingle;
        } else if (value.equals(ConfValueMode.InMulti.value)) {
            return InMulti;
        } else if (value.equals(ConfValueMode.Num.value)) {
            return Num;
        } else if (value.equals(ConfValueMode.PicTure.value)){
            return PicTure;
        }else {
            return null;
        }
    }

    @JsonValue
    @Override
    public String getValue() {
        return value;
    }

    public String getText() {
        return text;
    }

    public static Map<String, String> getAllValueModes() {
        Map<String, String> map = Maps.newHashMap();
        Stream.of(values()).forEach(mode -> map.put(mode.value, mode.text));
        return map;
    }

    public static List<String> getNames() {
        return Stream.of(values()).map(ConfValueMode::getText).collect(Collectors.toList());
    }
}
